import {HTTP} from "../utils/http";
class ClassicModel extends HTTP{
    // 获取最新一期
    getLatest(callback){
        this.request({
            url:"/classic/latest",
            success:res=>{
                let index=res.index;
                callback(res);
                wx.setStorageSync('latest', res.index)
            }
        })
    }
    // 获取下一期或者上一期
    getClassic(index,nextOrprevious,callback){
        let inx = (nextOrprevious == "next")?index + 1 :index - 1;
        const classic =wx.getStorageSync(this._getKey(inx));
        if(classic){
            callback(classic)
        }else{
            this.request({
            url:`/classic/${index}/${nextOrprevious}`,
            success:res=>{
                callback(res);
                wx.setStorageSync(this._getKey(res.index),res)
            }
        })
        }
        
    }
    isFirst(index){
        return index==1?true:false
    }
    
    isLatest(index){
        const latest = wx.getStorageSync('latest');
        return index==latest?true:false;
    }
    _getKey(index){
        return "classic" + index;
    }
    // 得到点赞过的数据
    getFavor(callback){
        this.request({
            url: "/classic/favor",
            success:res=>{
                callback(res)
            }
        })
    }
}
export {ClassicModel};